<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
  <title>融资合同复制</title>
</head>
<style>
	.fieldset{
		margin-top: 5px;
		margin-bottom: 0px
	}
	.layui-legend{
		background-color:#5fb878;
		font-size:15px !important;
		width:140px;
	}
	.layui-form-item {
	    margin-bottom: 5px;
	    clear: both;
	    *zoom: 1;
	}
	.layui-form-label{width: 180px;}
</style>
<body>
<div class="layui-fluid">
    <div class="layui-card">
	    <div class="layui-tab-item layui-show">
	    	<div style="padding-top:15px;">&nbsp;</div>
			<form class="layui-form" id="addInfo_form" lay-filter="addInfo_form">
			<fieldset class="layui-elem-field layui-field-title fieldset"  id="baseInfo">
			<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">项目基础信息  ></legend>				
			  <div style="margin-top:20px">
			  	<div class="layui-form-item">
			  		<div class="layui-inline">
				      	<label class="layui-form-label">申请公司</label>
				      	<div class="layui-input-inline">
							<input type="hidden" name="hrOrgid" value="${bindOrgId}">
							<input type="text" value="${bindOrgName}" style="border:0px;width:220px" readonly="readonly" class="layui-input">
				      	</div>
				    </div>
				    <div class="layui-inline">
				    	<label class="layui-form-label">申请部门</label>
			      		<div class="layui-input-inline">
			      			<input type="hidden" name="hrDeptid" value="${bindDeptId}">
							<input type="text" value="${bindDeptName}" style="border:0px;" readonly="readonly" class="layui-input">
			      		</div>
				    </div>
			  	</div>
			  	<div class="layui-form-item">			  		
				    <div class="layui-inline">
				    	<label class="layui-form-label">申请人</label>
			      		<div class="layui-input-inline">
			        		<input type="hidden" name="hrStaffApplyid" value="${SESSION_KEY_USER_DETAIL.hrStaffId }">
			        		<input type="text" name="staffname" value="${SESSION_KEY_USER_DETAIL.realName }" readonly="readonly" style="border:0px" autocomplete="off" class="layui-input">
			      		</div>
				    </div>
			    </div>
			  	<div class="layui-form-item">
			  		<div class="layui-inline">
					    <label class="layui-form-label">项目名称</label>
				      	<div class="layui-input-inline">
				      		<input type="text" name="proName" value="${contractInfoVo.proName}" maxlength="100" style="border:0px" readonly="readonly" autocomplete="off" class="layui-input">
					        <input type="hidden" name="proname" value="${contractInfoVo.proCode}" maxlength="100" style="border:0px" readonly="readonly" autocomplete="off" class="layui-input">
				      	</div>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-inline">
		            	<label class="layui-form-label">融资合同名称</label>
		            	<div class="layui-input-inline">
		            		<input type="text" name="contractName" value="${contractInfoVo.contractName}" placeholder="请输入融资合同名称" maxlength="100" lay-verify="required" class="layui-input">
		            	</div>
	        		</div>
				</div>	
				<div class="layui-form-item">
					<div class="layui-inline">
		            	<label class="layui-form-label">合同融资总额（万元）</label>
		            	<div class="layui-input-inline">
		            		<input type="text" id="finSum" onblur="arabiaToCN(this,2);" name="finSum" value="${contractInfoVo.finSum}" readonly="readonly" style="border:0px" autocomplete="off" class="layui-input">
		            	</div>
	        		</div>
				</div>		
				<div style="margin-top:20px">    
					 <div class="layui-form-item">
						<label class="layui-form-label">融资方案简介</label>
						<div class="layui-input-block">
							<textarea name="capSchemeMemos" class="layui-textarea" maxlength="1000"
								lay-verify="required" style="width:899px;height:90px;">${contractInfoVo.capSchemeMemo }</textarea>
						</div>
					 </div> 
				</div>	
			</div>
			</fieldset>
			<fieldset class="layui-elem-field layui-field-title fieldset"  id="finInformation">
	  			<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">金融机构明细 ></legend>
		  		<div class="layui-form-item">
					<div class="layui-inline">
				    	<label class="layui-form-label">关联审批通过单据</label>
				      	<div class="layui-input-inline">
				      		<select id="add_select_passFinId" lay-filter="add_select_passFinId" lay-verify="required" lay-search>
					      		<option value="">请选择</option>
				      				<c:if test="${not empty passFinList }">
				              			<c:forEach items="${passFinList}" var="proNames">
				              				<option value="${proNames.id }">${proNames.codes }</option>
					            		</c:forEach>
				              		</c:if>
				      		</select>
				      	</div>
				      	<div class="layui-input-inline" style="width:400px;vertical-align:middle;">
					      	<button type="button" class="layui-btn layui-btn-sm" id="addFinOrgBtn1" onclick="addFinOrgRow(this);"><i class="layui-icon">&#xe654;</i></button>
				      		<span style="color:#FF5722;">（注：请选择对应的单据后，点击"＋"进行添加）</span>
				      	</div>
				    </div>			    
				</div>		  		
		  		<c:forEach items="${contractInfoVo.contractBanks }" var="finOrgs" varStatus="status">
		  		<div id="finOrgRow${status.count}">
		  			<div>
		  				<div>
		  					<div class="layui-form-item">			  		
							    <div class="layui-inline width106" style="display:none">
							    	<label class="layui-form-label">${status.count}</label>
						      		<div class="layui-input-inline">
							      		<input type="hidden" name="finOrgShowInx" value="${status.count}"/>
						      		</div>
							    </div>
						    </div>
		  				</div>
		  			</div>		  			
		  		<div style="margin-top:10px">
					<div class="layui-form-item">
						<div class="layui-inline width106" style="display:none">
						<label class="layui-form-label"></label>
							<div class="layui-input-inline"> 	
							</div> 
						</div>		
					</div> 
					<fieldset class="layui-elem-field layui-field-title fieldset"  id="finOrgUnit">
					<legend style="margin-left:40px;font-size:15px;font-weight:bold;"></legend>
						<div style="margin-top:20px" id="subDiv">
							<div class="layui-form-item">
								<div class="layui-inline">
				            	<label class="layui-form-label">金融机构</label>
					            	<div class="layui-input-inline">
					            		<input type="text" name="finOrg" value="${finOrgs.finOrg}" style="border:0px;" readonly="readonly" class="layui-input">
					            		<input type="hidden" name="passFinCodes" value="${finOrgs.passFinId}"/>
					            	</div>
		          				</div>
		          				<div class="layui-inline">
							    <label class="layui-form-label">立项时间</label>
							      	<div class="layui-input-inline">
							      		<input type="text" name="setupDate" value="<fmt:formatDate value="${finOrgs.setupDate }" pattern="yyyy-MM-dd"/>" style="border:0px;" readonly="readonly" class="layui-input">
							      	</div>
								</div>	
								<div class="layui-inline" style="text-align:left">
									<label class="layui-form-label" style="width:10px"></label>		  		
								    <div class="layui-inline">
								    	<button type="button" class="layui-btn layui-btn-sm" <c:if test="${status.count == 1 && fn:length(contractInfoVo.contractBanks) == 1}">style="display:none"</c:if> id="delFinOrgBtn${status.count}" onclick="delFinOrgRow(this)"><i class="layui-icon">&#xe640;</i></button>
								    </div>
						    	</div>					
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
				            	<label class="layui-form-label">融资团队负责人</label>
					            	<div class="layui-input-inline">
					            		<input type="text" name="leader" value="${finOrgs.leader}" style="border:0px;" readonly="readonly" class="layui-input">
					            	</div>
		          				</div> 	
								<div class="layui-inline">
							    <label class="layui-form-label">承贷企业</label>
							      	<div class="layui-input-inline">
							      		<input type="text" name="coopName" value="${finOrgs.coopName}" style="border:0px;" readonly="readonly" class="layui-input">
							      		<input type="hidden" name="sgCoopId" value="${finOrgs.sgCoopId}" style="border:0px;" readonly="readonly" class="layui-input">
							      	</div>
								</div>					
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
						    	<label class="layui-form-label">融资类型</label>
							    	<div class="layui-input-inline">
							    		<c:if test="${finOrgs.capType == '1' }">
							    			<input type="text" name="capTypes" value="债权融资" style="border:0px;" readonly="readonly" class="layui-input">
							    			<input type="hidden" name="capType" value="1" style="border:0px;" readonly="readonly" class="layui-input">
							    		</c:if>
						      			<c:if test="${finOrgs.capType == '2' }">
						      				<input type="text" name="capTypes" value="股权融资" style="border:0px;" readonly="readonly" class="layui-input">
						      				<input type="hidden" name="capType" value="2" style="border:0px;" readonly="readonly" class="layui-input">
						      			</c:if>
						      			<c:if test="${finOrgs.capType == '3' }">
							    			<input type="text" name="capTypes" value="信托基金" style="border:0px;" readonly="readonly" class="layui-input">
							    			<input type="hidden" name="capType" value="3" style="border:0px;" readonly="readonly" class="layui-input">
							    		</c:if>
						      			<c:if test="${finOrgs.capType == '9' }">
						      				<input type="text" name="capTypes" value="其他" style="border:0px;" readonly="readonly" class="layui-input">
						      				<input type="hidden" name="capType" value="9" style="border:0px;" readonly="readonly" class="layui-input">
						      			</c:if>
									</div>
						    	</div>
						    	<div class="layui-inline">
							    	<label class="layui-form-label">融资金额（万元）</label>
						      		<div class="layui-input-inline">
						      			<input type="text" name="capAmount" onblur="arabiaToCN(this,2);" value="${finOrgs.capAmount}" style="border:0px;" readonly="readonly" class="layui-input">
						      		</div>
							    </div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
							    	<label class="layui-form-label">融资期限（含还本付息方式）</label>
						      		<div class="layui-input-inline">
						      			<input type="text" name="timeLimit" value="${finOrgs.timeLimit}" style="border:0px;" readonly="readonly" class="layui-input">
						      		</div>
							    </div>
							    <div class="layui-inline">
							    	<label class="layui-form-label">合同融资成本（%）</label>
						      		<div class="layui-input-inline">
						      			<input type="text" name="capCost" value="${finOrgs.capCost}" onblur="isNumberAndFloat1(this);" lay-verify="required|floatAmount" maxlength="11" autocomplete="off" class="layui-input">
						      		</div>
							    </div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
							    	<label class="layui-form-label">附加条件（含保证金或其他条件）</label>
						      		<div class="layui-input-inline">
						      			<input type="text" name="needMemo" value="${finOrgs.needMemo}" style="border:0px;" readonly="readonly" class="layui-input">
						      		</div>
							    </div>
							    <div class="layui-inline">
							    	<label class="layui-form-label">担保方式</label>
						      		<div class="layui-input-inline">
						      			<input type="text" name="bailMode" value="${finOrgs.bailMode}" style="border:0px;" readonly="readonly" class="layui-input">
						      		</div>
							    </div>
							</div>
			  				<div class="layui-form-item">
								<div class="layui-inline">
							    	<label class="layui-form-label">综合成本说明</label>
						      		<div class="layui-input-inline">
						      			<input type="text" name="multiCost" value="${finOrgs.multiCost}" style="border:0px;" readonly="readonly" class="layui-input">
						      		</div>
							    </div>
							    <div class="layui-inline">
							    	<label class="layui-form-label">预计到账日期</label>
						      		<div class="layui-input-inline">
						      			<input type="text" name="willArrivalDate" value="<fmt:formatDate value="${finOrgs.willArrivalDate }" pattern="yyyy-MM-dd"/>"  style="border:0px;" readonly="readonly" class="layui-input">
						      		</div>
							    </div>
							</div>
			  			</div>
		  			</fieldset>
				  		</div>
				  		</div>
				  	</c:forEach>
		  	</fieldset>	

			<fieldset class="layui-elem-field layui-field-title" style="margin-top: 15px;">
                 <legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">附件信息 ></legend>
                 <div style="margin-top:20px;">
	                 <div class="layui-form-item">
					    <label class="layui-form-label" style="width:350px;">支持pdf、excel、word、图片资料，可上传多个</label>
					</div>
	                 <div class="layui-form-item">
					    <label class="layui-form-label">附件资料（选填）</label>
					    <div class="layui-input-block">
					    	<div class="layui-upload">
				              	<button type="button" class="layui-btn" id="1-upload-more">上传</button>
		                		<div class="layui-upload-list" id="1-upload-more-list">
		                		<c:forEach items="${contractInfoVo.contractAtts }" var="fileAtt">								              			
		              				<div class="layui-upload-img-div" id="upload_img_${fileAtt.id }">
		              					<c:choose>
			              					<c:when test="${fileAtt.fileSuffix == '.jpg' or fileAtt.fileSuffix == '.jpeg' or fileAtt.fileSuffix == '.png'}">
				              					<img src="${fileHttpPre }/${fileAtt.filePath }" title="${fileAtt.fileName}" class="layui-upload-img">
				              				</c:when>
				              				<c:otherwise>
				              					<img src="${ctx}/resources/images/${fn:substring(fileAtt.fileSuffix,1,5)}.jpg" title="${fileAtt.fileName}" class="layui-upload-img">
				              				</c:otherwise>
		              					</c:choose>
		              					<div class="mask">
		              						<a href="javascript:void(0)" onclick="showImg('${fileHttpPre}/${fileAtt.filePath }');">查看</a>
		              						<a href="javascript:void(0)" onclick="del('${fileAtt.id}')">删除</a>
		              						<input type="hidden" value="1|${fileAtt.fileName}${fileAtt.fileSuffix }||${fileAtt.filePath }" id="fileAtt_${fileAtt.id}" name="fileAtts" ></input>
		              					</div>
		              					<p>${fileAtt.fileName}</p>
		              				</div>								              			
			              		</c:forEach>
		                		</div>
				            </div>
					    </div>
				  	</div>
				  </div>
            </fieldset>	
                 		   
			<div class="layui-form-item" style="position: fixed ! important; right: 30px; bottom:45%;z-index:10000;">
				<div class="layui-input-block">
		      		<button class="layui-btn layui-bg-blue layui-btn-normal layui-btn-lg  layui-btn-radius" type="button" lay-submit lay-filter="addInfo_form_submit" id="addInfo_form_submit">
		      		<i class="layui-icon layui-icon-ok layuiadmin-button-btn"></i>
		      		提交
		      		</button>
		      	</div>
		    </div>
			</form>			
  		</div>
	</div>
</div>
  <script>
	//静态资源路径前缀
	var staticPath = '${fileHttpPre}';
	var stateJSON = <infopub:dicJson groupNo="A00010028" />;
	var capTypeJSON = {"1":"债权融资","2":"股权融资","3":"信托基金","9":"其他"};
	
  layui.config({
    base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'set', 'upload', 'element', 'laydate'], function(){
    var $ = layui.$
    ,form = layui.form
    ,element = layui.element
    ,laydate = layui.laydate
    ,upload = layui.upload;
       
 	// 正则校验
	form.verify({
		//验证汉字
	    CHS:[
	    	/^[\u0391-\uFFE5]+$/
	    	,'只能输入汉字'
	  	],
	  	//名字校验
	  	COC: [
			/^[\u4e00-\u9fa5_a-zA-Z0-9]+$/
			,'请输入正确的名称'
	  	],
	  	//大于0的正整数
	  	intNumber:[
			/^[1-9]\d*$/
			,'请输入正确的数字'
	  	],
	  	//数字只能有两位小数
	  	floatNumber:[
			/^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			,'请输入正确的数字'
	  	],
	  	telNumber:[/^[1][3,4,5,7,8,9][0-9]{9}$/
			  		,'请输入正确的号码'
		],
	  	//数字大于等于0，并只能有两位小数
	  	floatAmount:[
			/^([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			//var pattern=/^((\d+\.\d*[1-9]\d{1})|(\d*[1-9]\d*\.\d{2}))$/; 
			,'请输入正确的数字'
	  	]
	});
	
	//多文件列表示例
    upload.render({
	      elem: '#1-upload-more'
	      ,url: basePath + '/contractInfo/uploadAtt/'
	      ,data: {
	    	  types:1
	    		}
	      ,multiple: true
	      ,accept: 'file'
	      ,acceptMime: 'application/zip,application/x-rar-compressed,image/jpeg,image/png,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/pdf'
	   	  ,before: function(obj){ //obj参数包含的信息
	   		    layer.load(); //上传loading
	   		  }
	      ,done: function(res){
	    	  //如果上传失败
	          if(res.code > 0){
	        	  
	        	  layer.closeAll('loading'); //关闭loading
	        	  return layer.msg(res.msg,{icon: 7});
	          }
	          //上传完毕
	   	  	  if(res.entity != null && res.entity.length > 0){
	   	  		
				for(var i in res.entity){
					var contractInfo = res.entity[i];
					var arr = contractInfo.split("|");
					var imgSrc = "";
					var suffix = arr[1].substring(arr[1].lastIndexOf(".")+1,arr[1].length);
					if(suffix == 'jpg' || suffix == 'png'){
						imgSrc = "${fileHttpPre}/"+arr[3];
					}else{
						imgSrc = "${ctx}/resources/images/"+suffix+".jpg";
					}
	        		$('#1-upload-more-list')
	        		.append('<div class="layui-upload-img-div" id="upload_img_'+arr[2]+'"><img src="'+imgSrc+'" title="'
	        				+ arr[1] +'" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\''+"${fileHttpPre}"
	        						+arr[3] +'\');">查看</a><a href="javascript:void(0)" onclick="del(\''
	        								+arr[2]+'\')";>删除</a></div><p>'+arr[1]+'</p><input type="hidden" value="'
	        								+contractInfo+'" id="fileAtt_'+arr[2]+'" name="fileAtts" ></input></div> ');
				}
		  	  }
	      }
	      ,allDone: function(obj){ //当文件全部被提交后，才触发
	    	  layer.closeAll('loading'); //关闭loading
	      }
	      ,error: function(){
	    	  layer.closeAll('loading'); //关闭loading
	          //上传失败
	          layer.msg("上传失败，请稍后再试~",{icon: 7});
	        }
	    });
   	//监听提交
  	form.on('submit(addInfo_form_submit)', function(data){
  		$("#addInfo_form_submit").removeAttr("lay-submit").removeClass("layui-bg-blue").addClass("layui-btn-disabled");
  		layer.load();
       	//提交 Ajax 成功后，静态更新表格中的数据
       	
       	$.ajax({
           	type : 'post',
			url : basePath + '/contractInfo/save',
           	data: $('#addInfo_form').serialize(),
			success:function(result){
				if(result.success){
					layer.closeAll('loading'); //关闭loading
					layer.msg('提交单据成功~',{icon: 1});
					//两秒后关闭当前页面
					setTimeout(function(){
						/**
						 * 查找父菜单，并刷新
						 */
						var topDoc = $(window.top.document);
						var path = basePath + '/contractInfo/list';
						// 获取页面名称
						var name = topDoc.find(".layui-nav-item [lay-href^='" + path + "']").text();
						if(name == '' || name == null){
							name = '融资合同';
						}
						window.parent.layui.index.openTabsPage(path, name);
						var iframe = window.parent.layui.admin.tabsBody(window.parent.layui.admin.tabsPage.index).find(".layadmin-iframe");
						iframe[0].contentWindow.location.reload(true);
						
						/**
						 * 关闭当前页
						 */
						var currPath = basePath + '/contractInfo/toCopy';
						var layid = topDoc.find("li[lay-id^='" + currPath + "']").attr('lay-id');
						window.parent.layui.element.tabDelete('layadmin-layout-tabs', layid);//关闭当前页
				        }, 2000);
				}else{
					layer.closeAll('loading'); //关闭loading
  					$("#addInfo_form_submit").removeClass("layui-btn-disabled").addClass("layui-bg-blue").attr("lay-submit","");
					layer.msg(result.msg,{icon: 7});
			  	}
			}
       	});
   	});  
 	// data-type事件
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  	
  });
		
	//新增金融机构一行
	function addFinOrgRow(t){
		var $ = layui.$;
		var form = layui.form;
		var passFinCode = $('#add_select_passFinId').val();
		if(passFinCode==null||passFinCode==undefined||passFinCode==""){
			layer.msg("请先选择单据编号",{icon: 7});
		}else{
			//获取所有该项目信息
			$.ajax({
				type : "POST", //提交方式  
				url : "${ctx}/contractInfo/getPassFinAllByCodes",//路径  
				data : {
					"codes" :passFinCode
				},//数据，这里使用的是Json格式进行传输  
				success : function(result) {//返回数据根据结果进行相应的处理 
					if(result.flag==true){
						
						var passFin = result.passFinAllByCodes;
						
						var medalHtml = '';
						medalHtml += '<div style="margin-top:20px">';
						medalHtml += '	<div class="layui-form-item">';
						medalHtml += '		<div class="layui-inline width106" style="display:none">';
						medalHtml += '		<label class="layui-form-label"></label>';   
						medalHtml += '			<div class="layui-input-inline">';  
						medalHtml += '			</div>'; 
						medalHtml += '		</div>';		
						medalHtml += '	</div>';  
						medalHtml += '	<fieldset class="layui-elem-field layui-field-title fieldset"  id="finOrgUnit">'; 
						medalHtml += '	 <legend style="margin-left:40px;font-size:15px;font-weight:bold;"></legend>';
						medalHtml += '	<div style="margin-top:20px" id="subDiv">';
						medalHtml += '	<div class="layui-form-item">';
						medalHtml += '		<div class="layui-inline">';   
						medalHtml += '		<label class="layui-form-label">金融机构</label>';   
						medalHtml += '			<div class="layui-input-inline">';    
						medalHtml += '				<input type="text" name="finOrg" value='+passFin.finOrg+' style="border:0px" readonly="readonly" class="layui-input">';    	
						medalHtml += '				<input type="hidden" name="passFinCodes" value="'+passFinCode+'"/>';	
						medalHtml += '			</div>';	
						medalHtml += '		</div>';     	
						medalHtml += '		<div class="layui-inline">';   
						medalHtml += '		<label class="layui-form-label">立项时间</label>';   
						medalHtml += '			<div class="layui-input-inline">';    
						medalHtml += '				<input type="text" name="setupDate" value='+layui.util.toDateString(passFin.setupDate,"yyyy-MM-dd")+' style="border:0px" readonly="readonly" class="layui-input">';    	
						medalHtml += '			</div>';   
						medalHtml += '		</div>';						
						medalHtml += '		<div class="layui-inline" style="text-align:left">';
						medalHtml += '		<label class="layui-form-label" style="width:10px"></label>';   
						medalHtml += '			<div class="layui-input-inline">'; 
						medalHtml += '				<button type="button" class="layui-btn layui-btn-sm" onclick="delFinOrgRow(this)"><i class="layui-icon">&#xe640;</i></button>';
						medalHtml += '			</div>';
						medalHtml += '		</div>';
						medalHtml += '	</div>';	
						medalHtml += '	<div class="layui-form-item">';      
						medalHtml += '		<div class="layui-inline">';  	
						medalHtml += '		<label class="layui-form-label">融资团队负责人</label>';       	
						medalHtml += '			<div class="layui-input-inline">';      	
						medalHtml += '				<input type="text" name="leader" value='+passFin.leader+' style="border:0px" readonly="readonly" class="layui-input">';
						medalHtml += '			</div>';   
						medalHtml += '		</div>';	
						medalHtml += '		<div class="layui-inline">';	
						medalHtml += '		<label class="layui-form-label">承贷企业</label>';     	
						medalHtml += '			<div class="layui-input-inline">';
						medalHtml += '				<input type="text" name="coopName" value='+passFin.coopName+' style="border:0px" readonly="readonly" class="layui-input">';
						medalHtml += '			    <input type="hidden" name="sgCoopId" value='+passFin.coopId+' />';					 
						medalHtml += '			</div>';   
						medalHtml += '		</div>';	
						medalHtml += '	</div>';      	
						medalHtml += '	<div class="layui-form-item">';      
						medalHtml += '		<div class="layui-inline">';       		
						medalHtml += '		<label class="layui-form-label">融资类型</label>';       	
						medalHtml += '			<div class="layui-input-inline">';
						medalHtml += '			<input type="text" value='+capTypeJSON[passFin.capType]+' style="border:0px;" readonly="readonly" class="layui-input">';
						medalHtml += '			<input type="hidden" name="capType" value='+passFin.capType+' />';
						medalHtml += '			</div>';   
						medalHtml += '		</div>';    	
						medalHtml += '		<div class="layui-inline width107">';	
						medalHtml += '		<label class="layui-form-label">融资金额（万元）</label>';     	
						medalHtml += '			<div class="layui-input-inline">';     		
						medalHtml += '				<input type="text" name="capAmount" value='+parseFloat(passFin.capAmount).toFixed(2)+' style="border:0px" readonly="readonly" class="layui-input">';   						 
						medalHtml += '			</div>';   
						medalHtml += '		</div>';    		
						medalHtml += '	</div>';		    	
						medalHtml += '	<div class="layui-form-item">';      
						medalHtml += '		<div class="layui-inline">';       		
						medalHtml += '		<label class="layui-form-label">融资期限（含还本付息方式）</label>';       	
						medalHtml += '			<div class="layui-input-inline">';  	
						medalHtml += '				<input type="text" name="timeLimit" value='+passFin.timeLimit+' style="border:0px" readonly="readonly" class="layui-input">';	
						medalHtml += '			</div>';   
						medalHtml += '		</div>';    	
						medalHtml += '		<div class="layui-inline">';	
						medalHtml += '		<label class="layui-form-label">合同融资成本（%）</label>';     	
						medalHtml += '			<div class="layui-input-inline">';     		
						medalHtml += '				<input type="text" name="capCost" value='+parseFloat(passFin.capCost).toFixed(2)+' onblur="isNumberAndFloat1(this);" lay-verify="required|floatAmount" maxlength="11" autocomplete="off" class="layui-input">';   						 
						medalHtml += '			</div>';   
						medalHtml += '		</div>';    		
						medalHtml += '	</div>';		      			
						medalHtml += '	<div class="layui-form-item">';      
						medalHtml += '		<div class="layui-inline">';       		
						medalHtml += '		<label class="layui-form-label">附加条件（含保证金或其他条件）</label>';       	
						medalHtml += '			<div class="layui-input-inline">';  	
						medalHtml += '				<input type="text" name="needMemo" value='+passFin.needMemo+' style="border:0px" readonly="readonly" class="layui-input">';	
						medalHtml += '			</div>';   
						medalHtml += '		</div>';    	
						medalHtml += '		<div class="layui-inline">';	
						medalHtml += '		<label class="layui-form-label">担保方式</label>';     	
						medalHtml += '			<div class="layui-input-inline">';     		
						medalHtml += '				<input type="text" name="bailMode" value='+passFin.bailMode+' style="border:0px" readonly="readonly" class="layui-input">';   						 
						medalHtml += '			</div>';   
						medalHtml += '		</div>';    		
						medalHtml += '	</div>';		
						medalHtml += '	<div class="layui-form-item">';      
						medalHtml += '		<div class="layui-inline">';       		
						medalHtml += '		<label class="layui-form-label">综合成本说明</label>';       	
						medalHtml += '			<div class="layui-input-inline">';  	
						medalHtml += '				<input type="text" name="multiCost" maxlength="2000" value='+passFin.multiCost+' style="border:0px" readonly="readonly" class="layui-input">';	
						medalHtml += '			</div>';   
						medalHtml += '		</div>';    	
						medalHtml += '		<div class="layui-inline">';	
						medalHtml += '		<label class="layui-form-label">预计到账日期</label>';     	
						medalHtml += '			<div class="layui-input-inline">';     		
						medalHtml += '				<input type="text" name="willArrivalDate" value='+layui.util.toDateString(passFin.willArrivalDate,"yyyy-MM-dd")+' style="border:0px" readonly="readonly" class="layui-input">';   						 
						medalHtml += '			</div>';   
						medalHtml += '		</div>';    		
						medalHtml += '	</div>';
						medalHtml += '		</div>';    		
						medalHtml += '	</div>';
						medalHtml += '	</fieldset>';
						medalHtml += '</div>';
						   
						$(t).parent().parent().parent().after(medalHtml);
												
						//合同融资总额
						var strFinSumBuffer = "";
						$('input[name="capAmount"]').each(function(){
							if(strFinSumBuffer==""||strFinSumBuffer==null){
								strFinSumBuffer = (parseFloat($(this).val())).toFixed(2);
							}else{
								strFinSumBuffer = (parseFloat(strFinSumBuffer) + parseFloat($(this).val())).toFixed(2);
							}
						});
						$('#finSum').val(strFinSumBuffer);
						
				        form.render();
					}else{
						layer.msg('数据通信异常~',{icon: 0});
					}
				}
			});
		} 
	}
	
	//删除金融机构一行
	function delFinOrgRow(t){
		var $ = layui.$;
		layui.layer.confirm('确定删除？',{icon:3, title :'提示'}, function(index){
			$(t).parent().parent().parent().parent().parent().remove();
			//减行时候重新计算合同融资总额
			var strFinSumBuffer = "";
			$('input[name="capAmount"]').each(function(){
				if(strFinSumBuffer==""||strFinSumBuffer==null){
					strFinSumBuffer = (parseFloat($(this).val())).toFixed(2);
				}else{
					strFinSumBuffer = (parseFloat(strFinSumBuffer) + parseFloat($(this).val())).toFixed(2);
				}
			});
			$('#finSum').val(strFinSumBuffer);
			layui.layer.close(index);			
 		});	
	}
	
	//删除文件
	function del(index){
		layui.$("#fileAtt_"+index).remove();
		layui.$("#upload_img_"+index).remove();
	}
  
	//根据url查看文件
	function showImg(url){
		var openWin = window.open(url,'','left=410,height=768, width=1024, top=200,  toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
	}
  	
	//根据项目编号带出所有审批通过的单据编号
	function getPassFinCodesByProId(proCode){
		var $ = layui.$
	  	,form = layui.form
	  	
			//获取所有该项目信息
			$.ajax({
				type : "POST", //提交方式  
				url : "${ctx}/contractInfo/getPassFinCodesByProId",//路径  
				data : {
					"proCode" :proCode
				},//数据，这里使用的是Json格式进行传输  
				success : function(result) {//返回数据根据结果进行相应的处理 
					if(result.flag==true){
						form.val('addInfo_form',result.passFinList); // 填充原值
						var passFinList = result.passFinList;
						
						//关联审批通过的单据
						var strPassFinCodesBuffer = "";						
						strPassFinCodesBuffer+= '<option value="">请选择</option>';
						layui.$.each(passFinList, function(i,item){
							if(item.codes != null){	
								strPassFinCodesBuffer+= '<option value='+item.id+'>'+item.codes+'</option>';
							}
				        });
						$('select[id^="add_select_passFinId"]').each(function(){
							$(this).append(strPassFinCodesBuffer)
						});
				        form.render();
					}else{
						layer.msg('数据通信异常~',{icon: 0});
					}
				} 
			});
		}
	
	//根据审批通过的单据编号带出所有该单据的审批通过信息
	function getPassFinByCode(code,showIdx){
		var $ = layui.$
	  	,form = layui.form
	  	
			//获取所有该项目信息
			$.ajax({
				type : "POST", //提交方式  
				url : "${ctx}/contractInfo/getPassFinAllByCodes",//路径  
				data : {
					"codes" :code
				},//数据，这里使用的是Json格式进行传输  
				success : function(result) {//返回数据根据结果进行相应的处理 
					if(result.flag==true){
						form.val('addInfo_form',result.passFinAllByCodes); // 填充原值
						var passFin = result.passFinAllByCodes;
						
						//金融机构
						var strFinOrgBuffer = "";										
						if(passFin.proCode != null && passFin.proName != null){								
							strFinOrgBuffer+= passFin.finOrg;
						}
						$('#finOrg'+showIdx+'').val(strFinOrgBuffer);
						//立项时间
						var strSetupDateBuffer = "";										
						if(passFin.proCode != null && passFin.proName != null){								
							strSetupDateBuffer+=layui.util.toDateString(passFin.setupDate,"yyyy-MM-dd")
						}
						$('#setupDate'+showIdx+'').val(strSetupDateBuffer);
						//融资团队负责人
						var strLeaderBuffer = "";										
						if(passFin.proCode != null && passFin.proName != null){								
							strLeaderBuffer+= passFin.leader;
						}
						$('#leader'+showIdx+'').val(strLeaderBuffer);
						//承贷企业
						var strCoopNameBuffer = "";										
						if(passFin.proCode != null && passFin.proName != null){								
							strCoopNameBuffer+= '<option value='+passFin.coopCode+' selected>'+passFin.coopName+'</option>'
						}
						$('#query-select-coopName').append(strCoopNameBuffer);
						$('#hidden_coopName'+showIdx+'').val(passFin.coopCode);
						//融资类型
						var strCapTypeBuffer = "";	
						if(passFin.proCode != null && passFin.proName != null){
							 if(passFin.capType=='1'){
								 strCapTypeBuffer+= '<option value='+1+' selected>债权融资</option>';										 
							 }else if(passFin.capType=='2'){
								 strCapTypeBuffer+= '<option value='+2+' selected>股权融资</option>';
							 }else if(passFin.capType=='3'){
								 strCapTypeBuffer+= '<option value='+3+' selected>信托基金</option>';
							 }else if(passFin.capType=='9'){
								 strCapTypeBuffer+= '<option value='+9+' selected>其他</option>';
							 }
						}
						$('#query-select-capType').append(strCapTypeBuffer);
						$('#hidden_capType'+showIdx+'').val(passFin.capType);					
						//融资金额
						var strCapAmountBuffer = "";										
						if(passFin.proCode != null && passFin.proName != null){								
							strCapAmountBuffer+= (parseFloat(passFin.capAmount)).toFixed(2);
						}
						$('#capAmount'+showIdx+'').val(strCapAmountBuffer);
						//融资期限
						var strTimeLimitBuffer = "";										
						if(passFin.proCode != null && passFin.proName != null){								
							strTimeLimitBuffer+= passFin.timeLimit;
						}
						$('#timeLimit'+showIdx+'').val(strTimeLimitBuffer);
						//合同融资成本
						var strCapCostBuffer = "";										
						if(passFin.proCode != null && passFin.proName != null){								
							strCapCostBuffer+= passFin.capCost;
						}
						$('#capCost'+showIdx+'').val(strCapCostBuffer);
						//附加条件
						var strNeedMemoBuffer = "";										
						if(passFin.proCode != null && passFin.proName != null){								
							strNeedMemoBuffer+= passFin.needMemo;
						}
						$('#needMemo'+showIdx+'').val(strNeedMemoBuffer);
						//担保方式
						var strBailModeBuffer = "";										
						if(passFin.proCode != null && passFin.proName != null){								
							strBailModeBuffer+= passFin.bailMode;
						}
						$('#bailMode'+showIdx+'').val(strBailModeBuffer);
						//综合成本说明
						var strMultiCostBuffer = "";										
						if(passFin.proCode != null && passFin.proName != null){								
							strMultiCostBuffer+= passFin.multiCost;
						}
						$('#multiCost'+showIdx+'').val(strMultiCostBuffer);
						//预计到账日期
						var strArrivalDateBuffer = "";										
						if(passFin.proCode != null && passFin.proName != null){								
							strArrivalDateBuffer+=layui.util.toDateString(passFin.willArrivalDate,"yyyy-MM-dd");
						}
						$('#willArrivalDate'+showIdx+'').val(strArrivalDateBuffer);
						//合同融资总额
						$('input[id^="capAmount"]').each(function(){
							strCapAmountBuffer+= (parseFloat($(this).val())).toFixed(2);						
						});
						$('#finSum').val(strCapAmountBuffer);
						
				        form.render();
					}else{
						layer.msg('数据通信异常~',{icon: 0});
					}
				} 
			});
		}
	
	//'请输入正确数字，且保留两位小数！'
	function isNumberAndFloat1(str) {
		var $ = layui.$, form = layui.form
		if (str.value == '' || str.value == null) {
			return;
		}
		var rgx = /^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;

		var boolrgx = rgx.test(str.value);// true 
		if (boolrgx) {
			return true;
		} else {
			str.value =0;
			layer.msg('请输入正确的数字，且保留两位小数！');
			return false;
		}
	}

  </script>
</body>
</html>

